<!DOCTYPE html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org" xmlns:v-on="http://www.w3.org/1999/xhtml"
      xmlns:v-if="http://www.w3.org/1999/xhtml">
<head th:replace="~{baseui/head :: head}">
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <meta name="description" content="动检通智慧云平台"/>
    <meta name="author" content="牧中(上海)物联网科技有限公司"/>
    <link rel="shortcut icon" href="/webjars/images/favicon.png"/>

    <title>牧中畜牧业大数据智慧云平台V1.0</title>


</head>
<body>
<!--顶部一级导航-->
<th:block th:replace="baseui/topheader :: topheader(1)"/>

<!--动检通菜单-->
<div id="topnav" th:replace="djt/partial/topnav :: topnav(3)"></div>


<div id="cl-wrapper">
    <!--左边导航-->
    <th:block th:replace="djt/partial/quarantine_left :: nav(34)"/>

    <div class="container-fluid" id="pcont">
        <div class="cl-mcont">
            <div class="row">
                <div class="col-md-12">
                    <div class="block-flat">
                        <div id="show" class="header from-group"><h3>合格发证</h3>
                        </div>

                        <div class="content">
                            <div class="table-responsive">
                                <div id="datatable_wrapper"
                                     class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                                    <div class="row">

                                        <div class="from-group">
                                            <div id="but" class="btn-group col-sm-2" style="width: 180px;float: left">
                                                <input type="hidden" id="hiddate" value="1"/>
                                                <button date-id="but1" type="button"
                                                        class="btn btn-default btn-sm"
                                                        onclick="SimpleSearch(1)">
                                                    日
                                                </button>
                                                <button date-id="but2" type="button" class="btn btn-default btn-sm"
                                                        onclick="SimpleSearch(2)">
                                                    周
                                                </button>
                                                <button date-id="but3" type="button" class="btn btn-default btn-sm"
                                                        onclick="SimpleSearch(3)">
                                                    月
                                                </button>
                                                <button date-id="but4" type="button" class="btn btn-default btn-sm"
                                                        onclick="SimpleSearch(4)">
                                                    季
                                                </button>
                                                <button date-id="but6" type="button" class="btn btn-default btn-sm"
                                                        onclick="SimpleSearch(6)">
                                                    年
                                                </button>
                                            </div>

                                            <div class="col-sm-2" style="width: 140px">
                                                <div class="input-group date datetime col-md-5 col-xs-7"
                                                     data-min-view="2" data-date-format="yyyy-mm-dd">
                                                    <input id="start" class="form-control" style="width: 90px;"
                                                           size="16"
                                                           type="text" value="" placeholder="开始时间" readonly>
                                                    <span class="input-group-addon btn btn-primary"><span
                                                            class="glyphicon glyphicon-th"></span></span>
                                                </div>
                                            </div>
                                            <div class="col-sm-2" style="width: 140px">
                                                <div class="input-group date datetime col-md-5 col-xs-7"
                                                     data-min-view="2" data-date-format="yyyy-mm-dd">
                                                    <input id="end" class="form-control" style="width: 90px;" size="16"
                                                           type="text" value="" placeholder="结束时间" readonly>
                                                    <span class="input-group-addon btn btn-primary"><span
                                                            class="glyphicon glyphicon-th"></span></span>
                                                </div>


                                            </div>

                                            <!--<option value="">养殖场名称</option>
                                            <option th:each=" breedfactory : ${factoryname}" th:text="${breedfactory.name}"
                                                    th:value="${breedfactory.name}"></option>-->
                                            <div class="col-sm-2" style="width: 150px">
                                                <select id="area" class="select2">
                                                    <option value="">所有区域</option>
                                                    <optgroup th:each="cityarea:${areaList}"
                                                              th:label="${cityarea.city}">
                                                        <option th:each="region:${cityarea.region}"
                                                                th:text="${region}" th:value="${region}"></option>
                                                    </optgroup>

                                                </select>

                                            </div>
                                            <div class="col-sm-2" style="width: 150px">
                                                <select id="type" class="select2">
                                                    <option value="0">动物种类</option>
                                                    <option value="1">猪</option>
                                                    <option value="2">牛</option>
                                                    <option value="3">羊</option>
                                                    <option value="4">家禽</option>

                                                </select>

                                            </div>

                                            <div class="col-sm-2" style="width: 150px">
                                                <!---2:已处理 -1：驳回 0：未提交 1：待处理 2：宰前检查 3：同步检疫 4：合格发证 ：5 发证-->
                                                <select id="status" class="select2">
                                                    <option value="-5">受理状态</option>
                                                    <option value="-1">已处理</option>
                                                    <option value="-1">驳回</option>
                                                    <option value="0">未提交</option>
                                                    <option value="1">待处理</option>
                                                    <option value="2">宰前检查</option>
                                                    <option value="3">同步检疫</option>
                                                    <option value="4">合格发证</option>
                                                    <option value="5">发证</option>
                                                </select>

                                            </div>
                                            <div class="col-sm-2" style="width: 100px">
                                                <button class="btn btn-primary" onclick="SearchBtn()">搜索</button>
                                            </div>

                                        </div>
                                    </div>
                                    <br/>

                                    <div class="row">
                                        <div class="col-sm-12">

                                            <!-- Table -->
                                            <table id="jqGrid"></table>
                                            <div id="jqGridPager"></div>

                                        </div>
                                    </div>


                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


        </div>
    </div>

</div>

<script type="text/javascript" src="/webjars/js/jquery.js"></script>
<script type="text/javascript" src="/webjars/js/jquery.gritter/js/jquery.gritter.js"></script>

<script type="text/javascript" src="/webjars/js/jquery.nanoscroller/jquery.nanoscroller.js"></script>
<script type="text/javascript" src="/webjars/js/behaviour/general.js"></script>
<script src="/webjars/js/jquery.ui/jquery-ui.js" type="text/javascript"></script>

<script type="text/javascript" src="/webjars/js/jquery.nestable/jquery.nestable.js"></script>
<script type="text/javascript" src="/webjars/js/bootstrap.switch/bootstrap-switch.min.js"></script>
<script type="text/javascript" src="/webjars/js/bootstrap.datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script src="/webjars/js/jquery.select2/select2.min.js" type="text/javascript"></script>
<script src="/webjars/js/skycons/skycons.js" type="text/javascript"></script>
<script src="/webjars/js/bootstrap.slider/js/bootstrap-slider.js" type="text/javascript"></script>
<script type="text/javascript" src="/webjars/js/jquery.niftymodals/js/jquery.modalEffects.js"></script>
<script type="text/javascript" src="/webjars/js/bootstrap.summernote/dist/summernote.min.js"></script>


<script type="text/javascript" src="/webjars/js/jquery.magnific-popup/dist/jquery.magnific-popup.min.js"></script>


<script src="/webjars/js/behaviour/voice-commands.js"></script>
<script src="/webjars/js/bootstrap/dist/js/bootstrap.min.js"></script>

<script type="text/ecmascript" src="/webjars/jqgrid/js/i18n/grid.locale-cn.js"></script>
<script type="text/ecmascript" src="/webjars/jqgrid/js/jquery.jqGrid.min.js"></script>
<script src="/webjars/js/laydate/laydate.js"></script>
<script src="//vuejs.org/js/vue.min.js"></script>
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
<script src="/webjars/js/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript">
    $(document).ready(function () {

        App.init();
        var sdata = {   // 构建查询需要的参数
            area: $("#area").val(),
            type: $("#type").val(),
            status: $("#status").val()
        };

        //grid
        $("#jqGrid").jqGrid({
            url: '/djt/quarantine/certificationIndex',
            mtype: "GET",
            styleUI: 'Bootstrap',
            datatype: "json",
            data: sdata,
            autowidth: true,
            colModel: [
                {label: '序号', name: 'butcherReport.id', key: true, width: 50, align: 'center', formatter: showid},
                {label: '区域', name: 'butcherFactory.region', width: 75, align: 'center'},
                {label: '编号', name: 'butcherReport.number', width: 75, align: 'center'},
                {label: '货主', name: 'butcherReport.owner', width: 75, align: 'center'},
                {label: '屠宰点', name: 'butcherReport.butcherFactoryName', width: 75, align: 'center'},
                {label: '申报人', name: 'butcherReport.userName', width: 75, align: 'center'},
                {label: '动物种类', name: 'butcherReport.productType', width: 80, align: 'center', formatter: showtype},
                {label: '数量及单位', name: 'butcherReport.quantity', width: 100, align: 'center', formatter: shownum},
                {label: '检疫证书', name: 'butcherReport.quarantineCertNumber', width: 75, align: 'center'},
                {label: '同步检疫合格数', name: 'butcherReportsForm.syncQualifiedQuantity', width: 120, align: 'center'},
                {label: '同步检疫不合格数', name: 'butcherReportsForm.syncUnqualifiedQuantity', width: 120, align: 'center'},
                {label: '状态', name: 'butcherReport.status', width: 75, align: 'center', formatter: showstatus},
                {label: '日期', name: 'butcherReport.date', width: 100, align: 'center', formatter: ShowDate},
                {label: '详细', width: 100, formatter: ShowOpertator, align: 'center'}
            ],
            viewrecords: true,
            height: 350,
            rowNum: 20,
            pager: "#jqGridPager"
        });

    });
    function ShowDate(cellvalue, options, rowObject) {
        if (cellvalue != null && cellvalue != "") {
            var timestamp4 = new Date(cellvalue);
            var dt = timestamp4.toLocaleDateString().replace(/\//g, "-") + " " + timestamp4.toTimeString().substr(0, 8);
            return dt;
        } else {
            return "";
        }
    }

    /* var start = {
     elem: '#start',
     format: 'YYYY/MM/DD hh:mm:ss',

     max: '2099-06-16 23:59:59', //最大日期
     istime: true,
     istoday: false,
     choose: function (datas) {
     end.min = datas; //开始日选好后，重置结束日的最小日期
     end.start = datas //将结束日的初始值设定为开始日
     }
     };
     var end = {
     elem: '#end',
     format: 'YYYY/MM/DD hh:mm:ss',
     max: '2099-06-16 23:59:59',
     istime: true,
     istoday: false,
     choose: function (datas) {
     start.max = datas; //结束日选好后，重置开始日的最大日期
     }
     };
     laydate(start);
     laydate(end);*/

    /*    function change(num) {
     $("#hiddate").val(num);
     $("button[date-id = but" + num + "]").addClass("active");
     $("button[date-id = but" + num + "]").siblings().removeClass("active");
     }*/

    function SearchBtn() {
        var time1 = $("#start").val();
        var time2 = $("#end").val();
        var area = $("#area").val();
        var type = $("#type").val();
        var status = $("#status").val();
        if (time1 == "") {
            time1 = new Date("2000-01-01 :00:00:00");
        } else {
            time1 = new Date(time1);
        }
        if (time2 == "") {
            time2 = new Date();
        } else {
            time2 = new Date(time2);
        }
        if (area == "") {
            area = null;
        }
        if (type == "") {
            type = 0;
        }
        if (status == "") {
            status = -5;
        }
        var sdata = {   // 构建查询需要的参数
            start: time1,
            end: time2,
            area: area,
            type: type,
            status: status
        };

        var postData = $("#jqGrid").jqGrid("getGridParam", "postData");

        $.extend(postData, sdata);

        $("#jqGrid").jqGrid("setGridParam", {
            search: true    // (6)将jqGrid的search选项设为true
        }).trigger("reloadGrid", [{page: 1}]);   // (7)重新载入Grid表格，以使上述设置生效

    }

    var SimpleSearch = function (num) {
        var end = new Date();
        var start = new Date();
        switch (num) {
            case 1 :
                start = new Date(new Date() - 24 * 60 * 60 * 1000);
                break;
            case 2:
                start = new Date(new Date() - 7 * 24 * 60 * 60 * 1000);
                break;
            case 3:
                start = new Date(new Date() - 30 * 24 * 60 * 60 * 1000);
                break;
            case 4:
                start = new Date(new Date() - 4 * 30 * 24 * 60 * 60 * 1000);
                break;
            case 5:
                start = new Date(new Date() - 6 * 30 * 24 * 60 * 60 * 1000);
                break;
            case 6:
                start = new Date(new Date() - 12 * 30 * 24 * 60 * 60 * 1000);
                break;
        }
        var sdata = {   // 构建查询需要的参数
            start: start,
            end: end,
            area: $("#area").val(),
            type: $("#type").val(),
            status: $("#status").val()
        };

        var postData = $("#jqGrid").jqGrid("getGridParam", "postData");

        $.extend(postData, sdata);

        $("#jqGrid").jqGrid("setGridParam", {
            search: true    // (6)将jqGrid的search选项设为true
        }).trigger("reloadGrid", [{page: 1}]);   // (7)重新载入Grid表格，以使上述设置生效

    }

    function showid(cellvalue, options, rowObject) {
        return cellvalue == -1 ? "合计" : cellvalue;

    }
    function showtype(cellvalue, options, rowObject) {
        /*1、猪 2、牛 3、羊 4、家禽*/
        switch (cellvalue) {
            case 1:
                return "猪";
                break;
            case 2:
                return "牛";
                break;
            case 3:
                return "羊";
                break;
            case 4:
                return "家禽";
                break;
            default :
                return "";

        }
    }
    /*-2:已处理 -1：驳回 0：未提交 1：待处理 2：宰前检查 3：同步检疫 4：合格发证 ：5 发证*/
    function showstatus(cellvalue, options, rowObject) {
        switch (cellvalue) {
            case 1:
                return "待处理";
                break;
            case 2:
                return "宰前检查";
                break;
            case 3:
                return "同步检疫";
                break;
            case 4:
                return "合格发证";
                break;
            case 5:
                return "发证";
                break;
            case -1:
                return "驳回";
                break;
            case -2:
                return "已处理";
                break;
            case 0:
                return "未提交";
                break;
            default :
                return "";

        }
    }


    function shownum(cellvalue, options, rowObject) {
        switch (rowObject.butcherReport.unit) {
            case 1:
                return cellvalue + "头";
                break;
            case 2:
                return cellvalue + "只";
                break;
            case 3:
                return cellvalue + "羽";
                break;
            case 4:
                return cellvalue + "克";
                break;
            case 5:
                return cellvalue + "毫升";
                break;
            case 6:
                return cellvalue + "头份";
                break;
            case 7:
                return cellvalue + "kg";
                break;
        }

    }

    function ShowOpertator(cellvalue, options, rowObject) {
        var link;
        var row = JSON.stringify(rowObject);

        link = "<button type='button' class='btn btn-default' id='" + row + "' onclick='select(this.id)'>查看</button>";
        return rowObject.id == -1 ? "" : link;
    }

    function select(data) {
        var json = JSON.parse(data);
        var type = showtype(json.butcherReportsForm.productType, null, null);
        var status = showstatus(json.butcherReport.status, null, null);
        var timestamp4 = new Date();
        var dt = timestamp4.toLocaleDateString().replace(/\//g, "-") + " " + timestamp4.toTimeString().substr(0, 8);
        var unit = shownum(json.butcherReportsForm.quantity, null, json);
        layui.use(['laypage', 'layer'], function () {
            var $ = layui.jquery, layer = layui.layer;
            layer.open({
                type: 2,
                skin: 'layui-layer-lan',
                area: ['800px', '500px'],
                content: ['/djt/quarantine/certificationpage', 'no'],
                success: function (layero, index) {
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']];

                    body.find("#applyUserName").text(json.butcherReportsForm.applyUserName);
                    body.find("#sourceName").text(json.butcherReportsForm.sourceName);
                    body.find("#productType").text(type);
                    body.find("#quantity").text(unit);
                    body.find("#butcherFactoryName").text(json.butcherReportsForm.butcherFactoryName);
                    body.find("#vetUserName").text(json.butcherReportsForm.vetUserName);
                    body.find("#syncQualifiedQuantity").text(json.butcherReportsForm.syncQualifiedQuantity);
                    body.find("#syncUnqualifiedQuantity").text(json.butcherReportsForm.syncUnqualifiedQuantity);
                    body.find("#beforeSlaughterHarmlessTreatment").text(json.butcherReportsForm.beforeSlaughterHarmlessTreatment);
                    body.find("#quarantineCertNumber").text(json.butcherReport.quarantineCertNumber);
                    body.find("#syncSlaughterHarmlessTreatment").text(json.butcherReportsForm.syncSlaughterHarmlessTreatment);
                    body.find("#status").text(status);

                }
            });

        });
    }

</script>


</body>
</html>
